package com.urea.web.controller.urea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.urea.system.domain.vo.FleetUserVo;
import com.urea.system.service.IFleetUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.enums.BusinessType;
import com.urea.system.domain.Fleet;
import com.urea.system.service.IFleetService;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.common.core.page.TableDataInfo;

/**
 * 车队Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/fleet")
@Api(tags = "车队信息")
public class FleetController extends BaseController
{
    @Autowired
    private IFleetService fleetService;
    @Autowired
    private IFleetUserService fleetUserService;

    /**
     * 查询车队列表
     */
//    @PreAuthorize("@ss.hasPermi('fleet:list')")
    @GetMapping("/list")
    @ApiOperation("查看车队用户列表")
    public TableDataInfo list(FleetUserVo vo)
    {
        startPage();
        List<FleetUserVo> list = fleetUserService.selectFleetUserList(vo);
        return getDataTable(list);
    }

    /**
     * 车队用户列表
     * @param vo
     * @return
     */
    @GetMapping("/userList")
    @ApiOperation("用户管理-车队用户列表")
    public TableDataInfo userList(FleetUserVo vo)
    {
        startPage();
        List<FleetUserVo> list = fleetUserService.queryFleetUserList(vo);
        return getDataTable(list);
    }

    /**
     * 车队添加用户信息
     * @param vo 用户信息
     * @return 结果
     */
    @PostMapping("/bind")
    @ApiOperation("车队添加车队成员")
    public AjaxResult bind(@RequestBody List<FleetUserVo> vo)
    {
        fleetUserService.bindFleetUser(vo);
        return success();
    }

    /**
     * 车队删除用户信息
     * @param vo 用户信息
     * @return 结果
     */
    @PostMapping("/unbind")
    @ApiOperation("删除车队成员")
    public AjaxResult unbind(@RequestBody FleetUserVo vo)
    {
        fleetUserService.unbind(vo);
        return success();
    }

    /**
     * 导出车队列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:export')")
    @Log(title = "车队", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fleet fleet)
    {
        List<Fleet> list = fleetService.selectFleetList(fleet);
        ExcelUtil<Fleet> util = new ExcelUtil<Fleet>(Fleet.class);
        util.exportExcel(response, list, "车队数据");
    }

    /**
     * 获取车队详细信息
     */
//    @PreAuthorize("@ss.hasPermi('fleet:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取车队信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fleetService.selectFleetById(id));
    }

    /**
     * 新增车队
     */
//    @PreAuthorize("@ss.hasPermi('fleet:add')")
    @Log(title = "车队", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新建车队")
    public AjaxResult add(@RequestBody FleetUserVo vo)
    {
        fleetService.insertFleet(vo);
        return success();
    }

    /**
     * 修改车队
     */
//    @PreAuthorize("@ss.hasPermi('fleet:edit')")
    @Log(title = "车队", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    @ApiOperation("修改车队信息")
    public AjaxResult edit(@RequestBody Fleet fleet)
    {
        return toAjax(fleetService.updateFleet(fleet));
    }

    /**
     * 删除车队
     */
    @PreAuthorize("@ss.hasPermi('fleet:remove')")
    @Log(title = "车队", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fleetService.deleteFleetByIds(ids));
    }

    /**
     * 获取所有车队信息
     * @return 车队信息
     */
    @GetMapping("/queryFleetList")
    @ApiOperation("获取所有车队信息")
    public AjaxResult queryFleetList(){
        return AjaxResult.success(fleetService.queryFleetList());
    }



}
